home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / rss / xrealloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  1.2 KB  |  60 lines

  1. /*
  2. \funcref{xrealloc}{VOIDP xrealloc (\params)}
  3.     {
  4.         {VOIDP} {ptr} {pointer to previously allocated memory, or NULL}
  5.         {int} {size} {new requested size, or 0}
  6.     }
  7.     {pointer to reallocated memory}
  8.     {error()}
  9.     {xstrdup()}
  10.     {xrealloc.c}
  11.     {
  12.         {\em xrealloc()} attempts to reallocate the memory pointed to by {\em
  13.         ptr}. If {\em ptr} is NULL, {\em xrealloc()} simply behaves like {\em
  14.         malloc()}. When allocation indicates failure, {\em error()} is called
  15.         to terminate the program with an appropriate message.
  16.  
  17.         The new requested size may be zero. In this case, {\em xrealloc()}
  18.         frees the memory associated with {\em ptr}.
  19.     }
  20. */
  21.  
  22.  
  23. #include <malloc.h>
  24. #include "icrssdef.h"
  25.  
  26. void *xrealloc (void *ptr, int size)
  27. {
  28.     register void
  29.         *newptr;
  30.  
  31.     if (! size)
  32.     {
  33.         if (ptr)
  34.             free (ptr);
  35.         return (NULL);
  36.     }
  37.  
  38. #ifdef MSDOS
  39.     newptr = malloc (size);
  40. #else
  41.     if (ptr)
  42.         newptr = realloc (ptr, size);
  43.     else
  44.         newptr = malloc (size);
  45. #endif
  46.  
  47.     if (! newptr)
  48.         error ("out of memory");
  49.  
  50. #ifdef MSDOS
  51.     if (ptr)
  52.     {
  53.         memcpy (newptr, ptr, size);
  54.         free (ptr);
  55.     }
  56. #endif
  57.  
  58.     return (newptr);
  59. }
  60.